package com.startup.yellocar.dao;
import org.hibernate.SessionFactory;
import java.util.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;
import com.startup.yellocar.dto.KittyDTO;
@Repository
@Transactional
public class KittyDAO {
@Autowired
protected SessionFactory sessionFactory;
@Transactional
public void insert(KittyDTO kittyDTO){
sessionFactory.getCurrentSession().save(kittyDTO);
}
@Transactional
public void update(KittyDTO kittyDTO){
sessionFactory.getCurrentSession().update(kittyDTO);
}
@Transactional
public KittyDTO get(int id) {return (KittyDTO) sessionFactory.getCurrentSession().get(KittyDTO.class,id);
}
@SuppressWarnings("unchecked")
@Transactional
public List<KittyDTO> getAll() {return (List<KittyDTO>) sessionFactory.getCurrentSession().createQuery("Select t from KittyDTO t").list();
}
@Transactional
public void delete(KittyDTO kittyDTO){
sessionFactory.getCurrentSession().delete(kittyDTO);
}
}
